package com.zhuanzhuan.hero.user.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * @ClassName UserSexEnum
 * @Description
 * @Author hanjunjun
 * @Date 2024/6/20 20:12
 */
@Getter
public enum UserSexEnum {
    MAN(1, "男"),
    WOMAN(2, "女")
    ;

    private final Integer code;

    private final String name;

    UserSexEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public static String getNameByCode(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        return Arrays.stream(UserSexEnum.values())
            .filter(anEnum -> anEnum.getCode().equals(code))
            .findFirst()
            .orElseThrow(() -> new RuntimeException("getNameByCode异常"))
            .getName();
    }
}
